<?php

require_once(REAL_PATH."/classes/post/mapper/mapper.php");
require_once(REAL_PATH."/classes/post/helpers/factory.php");
abstract class post_Abstract extends content_Abstract{
    
    protected $activ = 1; // mostenit din content
    protected $owner = 0;
    protected $keywords = '';
    protected $title = '';
    protected $teaser = '';

    static function getCollection( $type ) {
        return post_HelperFactory::getCollection( $type );
    }
    function collection() {
        return self::getCollection( get_class( $this ) );
    }

    //setare
    public function setOwner($val) {
        $this->owner = $val;
    }

    public function setKeywords($val) {
        $this->keywords = $val;
    }

    public function setTitle($val) {
        $this->title = $val;
    }

    public function setTeaser($val) {
        $this->teaser = $val;
    }
    //getare
    public abstract  function getUrl();

    public function getLink(array $settings){
        $url = $this->getUrl();
        $text = $this->title;
        $title = htmlspecialchars($this->title);        
        $settingsText = "";
        if(isset ($settings['text'])){
            $text = $settings['text'];
            unset($settings['text']);
        }

        if(isset ($settings['title'])){
            $title = $settings['title'];
            unset($title);
        }

        if(isset ($settings) && is_array($settings) && count($settings) > 0){
            foreach ($settings as $key => $value){
                $settingsText = "$key='{$value}'";
            }
        }
        $link = '<a href="'.$this->getUrl().'" title="'.$title.'" alt="'.$title.'" '.$settings.'>'.$text.'</a>';
        return $link;
    }


    public function getOwner() {
        return $this->owner;
    }

    public function getKeywords() {
        return $this->keywords;
    }

    public function getTitle() {
        return $this->title;
    }

    public function getTeaser() {
        if(!isset ($this->teaser) || trim($this->teaser) == ""){
            $teaser = substr(strip_tags($this->body), 0, 200);
            $this->teaser = $teaser;
            unset($teaser);
        }        
        return $this->teaser;
    }
    
}

?>
